package com.leetcode.demo19;

class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }

public class Solution {

/*    public ListNode removeNthFromEnd(ListNode head, int n) {   //n 是倒数第n个节点
        ListNode dummy = new ListNode(0);  //创建一个哑结点
        dummy.next = head;
        int length  = 0;
        ListNode first = head;
        while (first != null) {  //统计链表的长度
            length++;
            first = first.next;
        }
        length -= n;    //得到要删除的元素前面有多少个元素
        first = dummy;  //first移动到哑结点
        while (length > 0) {  // 循环找到要删除的元素的位置
            length--;
            first = first.next;
        }
        first.next = first.next.next;
        return dummy.next;
    }*/

/*    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0);
        dummy.next = head;
        ListNode first = dummy;
        ListNode second = dummy;
        //第一个指针先移动 n+1 步
        for (int i = 0; i < n + 1 ; i++) {
            first = first.next;
        }
        //第一个指针移动n步之后，两个指针同时移动，直到第一个指针到达终点停止遍历
        while (first != null) {
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        return dummy.next;
    }*/

}
